package icu.zhhll.excel.util;

import net.coobird.thumbnailator.Thumbnails;

import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;

/**
 * 图片压缩
 *
 * @author zh
 * @date 2023/9/12 15:07
 */
public class ImageUtils {

    /**
     * compressImage
     *
     * @param path       图片路径
     * @param suffix     压缩文件的后缀
     * @param outputFile 输出文件路径
     * @param scale      缩放因子
     * @return
     */
    public static void compressImage(String path,
                                     String suffix,
                                     String outputFile,
                                     double scale) throws IOException {
        BufferedImage image = Thumbnails.of(path)
                .scale(scale)
                .outputFormat(suffix)
                .asBufferedImage();
        ImageIO.write(image, suffix, new File(outputFile));
    }
}
